package com.arara.model;

import java.sql.CallableStatement;
import java.sql.SQLException;
import java.sql.Types;

import com.arara.controller.vo.Aluno;
import com.arara.controller.vo.IUsuario;
import com.arara.controller.vo.Professor;

public class UsuarioDAO {
	
	private static CallableStatement callableStatement = null;
	
	public static IUsuario login(String email, String senha){
		try {
			callableStatement = BD.getConnection().prepareCall("{CALL SP_S_ARA_USUARIO_TIPO(?, ?)}");
			callableStatement.setString(1, email);
			callableStatement.registerOutParameter(2, Types.CHAR);
			callableStatement.execute();
			String tipo = callableStatement.getString(2);
			if (tipo.equals("A")){
				Aluno aluno = AlunoDAO.getUserLogin(email, senha);
				return aluno;
			}else if (tipo.equals("P")){
				Professor professor = ProfessorDAO.getUserLogin(email, senha);
				return professor;
			} else return null;
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			return null;
		}
	}
}
